package com.ptrsystem.siatd.controllers;

import com.ptrsystem.siatd.dao.logica.logUserLogica;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class LogUsuariosController {

    @Autowired
    private logUserLogica logica;

    @RequestMapping(value = "logUsuario.htm", method = RequestMethod.POST)
    private String LogUser(@RequestParam("user") String user, @RequestParam("pass") String Pass, HttpServletRequest req) {
        String ret = "Error";
        List<Map> rt = logica.verificaLogUser(user, Pass);
        if (rt.size() > 0) {
            ret = "Main";
            req.getSession().setAttribute("usuario", rt.get(0).get("dat_usu"));
            req.getSession().setAttribute("dni", rt.get(0).get("dni"));
            req.getSession().setAttribute("nomUniDep", rt.get(0).get("nomUniDepInt"));
            req.getSession().setAttribute("nomUniPad", rt.get(0).get("nomUniPadInt"));
            logica.getRegistroSistema(rt.get(0).get("cod_acc").toString(), req);
        }
        return ret;
    }

}
